<template>
  <div>
    <!-- 列表页面 -->
    <div class="container" >
      <div class="title">
        <span>选择销售商品</span> <span class="back" @click="back"> <i class="iconfont icon-fanhui"></i> 返回 </span>
      </div>
      <el-divider></el-divider>
<!--      <div class="title">货品列表</div>-->
      <!-- 表格 -->
      <lin-table

        style="margin-top: 20px"
        class="title"
        :tableColumn="tableColumn"
        :tableData="tableData"
        :operate="operate"
        @handleEdit="handleEdit"
        @handleDelete="handleDelete"
        @row-click="rowClick"
        v-loading="loading"
      ></lin-table>
    </div>

    <!--    &lt;!&ndash; 编辑页面 &ndash;&gt;-->
    <!--    <book-modify v-else @editClose="editClose" :editBookID="editBookID"></book-modify>-->
    <!--    <button>sssdsdas</button>-->
  </div>
</template>

<script>

import LinTable from '@/component/base/table/lin-table'
import shopStock from '@/model/shopStock'


export default {
  name: 'shop-stock-list',
  components: {
    LinTable,
  },
  data() {
    return {
      tableColumn: [{ prop: 'goods_name', label: '商品名' }, { prop: 'stock_value', label: '库存量' }, { prop: 'shop_name', label: '商店' }],
      tableData: [],
      operate: [],
      showAdd: false,
      editBookID: 1,
    }
  },
  async created() {
    this.loading = true
    await this.getStocks()
    this.operate = [
      { name: '选择', func: 'handleEdit', type: 'primary' },
    ]
    this.loading = false
    console.log(this.tableData)
  },

  methods: {
    back() {
      this.$emit('back')
    },
    async getStocks() {
      try {
        const shopStocks = await shopStock.getShopStocks()
        this.tableData = shopStocks
        console.log(shopStocks)
      } catch (error) {
        if (error.code === 10020) {
          this.tableData = []
        }
      }
    },
    handleAdd(val) {
      // console.log('val', val)
      this.showAdd = true
      // this.editBookID = val.row.id
    },
    handleDelete(val) {
      // this.$confirm('此操作将永久删除该图书, 是否继续?', '提示', {
      //   confirmButtonText: '确定',
      //   cancelButtonText: '取消',
      //   type: 'warning',
      // }).then(async () => {
      //   const res = await book.deleteBook(val.row.id)
      //   if (res.code < window.MAX_SUCCESS_CODE) {
      //     this.getBooks()
      //     this.$message({
      //       type: 'success',
      //       message: `${res.message}`,
      //     })
      //   }
      // })
    },
    handleEdit(val) {
      console.log(val)
      this.$emit('backWithRow', val)
      // this.showAdd = false
    },
    rowClick() {},
    editClose() {
      // this.showEdit = false
      // this.getBooks()
    },
  },
}
</script>

<style lang="scss" scoped>

.el-divider--horizontal {
  margin: 0;
}

.container {
  padding: 0 30px;
  .title {
    height: 59px;
    line-height: 59px;
    color: $parent-title-color;
    font-size: 16px;
    font-weight: 500;
    text-indent: 40px;

    .back {
      float: right;
      margin-right: 40px;
      cursor: pointer;
    }
  }

  .wrap {
    padding: 20px;
  }

  .submit {
    float: left;
  }
}
</style>
